import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vitePluginCompression from 'vite-plugin-compression'
import path from 'path'

const viteBaseConfig = (BASEURL: string) => {
    return defineConfig({
        plugins: [vue(), vitePluginCompression()], // vitePluginCompression gzip 压缩打包
        optimizeDeps: {
            exclude: []
        },
        server: {
            proxy: {
                '/api': {
                    target: BASEURL,
                    changeOrigin: true,
                    rewrite: path => path.replace(/^\/api/, '')
                }
            }
        },
        resolve: {
            alias: {
                '@': path.resolve(__dirname, '../src')
            }
        },
        build: {
            rollupOptions: {
                output: {
                    manualChunks: (id: string) => { // 分包策略
                        if (id.includes('node_module')) {
                            return 'vendor'
                        }
                    }
                }
            }
        }
    })
}

export default viteBaseConfig